<template>
  <div class="user-avatars">
    <div class="avatars-container">
      <div 
        v-for="(user, index) in userList" 
        :key="index"
        class="avatar-item"
        :style="{ '--delay': index * 0.1 + 's' }"
        @click="handleAvatarClick(user)"
      >
        <div class="avatar-wrapper">
          <img :src="user.avatar" :alt="user.name" class="avatar-image" />
          <div class="avatar-status" :class="user.status"></div>
        </div>
        <span class="avatar-label">{{ user.label }}</span>
      </div>
      
      <!-- 中间的分享按钮 -->
      <div class="share-button" @click="handleShare">
        <div class="share-icon">
          <span class="plus-icon">+</span>
        </div>
        <span class="share-label">分享你也刻</span>
      </div>
    </div>
    
    <!-- 分享模态框 -->
    <ShareModal 
      :visible="showShareModal" 
      @close="handleCloseShareModal"
      @submit="handleShareSubmit"
    />
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { ElMessage } from 'element-plus'
import ShareModal from './ShareModal.vue'

// 用户数据
const userList = ref([
  { 
    avatar: '/src/assets/imgs/avatar_login.png', 
    name: '千饭了', 
    label: '千饭了',
    status: 'online'
  },
  { 
    avatar: '/src/assets/imgs/my_people.png', 
    name: '过生日', 
    label: '过生日',
    status: 'online'
  },
  { 
    avatar: '/src/assets/imgs/avatar_unlogin.png', 
    name: '千饭了2', 
    label: '千饭了',
    status: 'offline'
  },
  { 
    avatar: '/src/assets/imgs/avatar_login.png', 
    name: '过生日2', 
    label: '过生日',
    status: 'online'
  }
])

// 分享模态框状态
const showShareModal = ref(false)

const handleAvatarClick = (user) => {
  ElMessage.info(`点击了用户：${user.name}`)
}

const handleShare = () => {
  showShareModal.value = true
}

const handleCloseShareModal = () => {
  showShareModal.value = false
}

const handleShareSubmit = (shareData) => {
  console.log('分享提交成功:', shareData)
  ElMessage.success('分享发布成功！')
  showShareModal.value = false
}
</script>

<style scoped>
.user-avatars {
  padding: 0 16px 20px;
  display: flex;
  justify-content: center;
}

.avatars-container {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
}

.avatar-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  transition: transform 0.3s ease;
  animation: fadeInUp 0.6s ease var(--delay) both;
}

.avatar-item:hover {
  transform: translateY(-4px);
}

.avatar-wrapper {
  position: relative;
  margin-bottom: 8px;
}

.avatar-image {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  transition: transform 0.3s ease;
}

.avatar-item:hover .avatar-image {
  transform: scale(1.1);
}

.avatar-status {
  position: absolute;
  bottom: 2px;
  right: 2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid #fff;
}

.avatar-status.online {
  background-color: #4CAF50;
}

.avatar-status.offline {
  background-color: #ccc;
}

.avatar-label {
  font-size: 12px;
  color: #666;
  text-align: center;
  font-weight: 500;
}

.share-button {
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  transition: transform 0.3s ease;
  margin: 0 8px;
  animation: fadeInUp 0.6s ease 0.4s both;
}

.share-button:hover {
  transform: translateY(-4px);
}

.share-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, #4CAF50 0%, #8BC34A 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 8px;
  box-shadow: 0 4px 12px rgba(76, 175, 80, 0.3);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.share-button:hover .share-icon {
  transform: scale(1.1);
  box-shadow: 0 6px 16px rgba(76, 175, 80, 0.4);
}

.plus-icon {
  color: white;
  font-size: 20px;
  font-weight: bold;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.share-label {
  font-size: 12px;
  color: #4CAF50;
  text-align: center;
  font-weight: 600;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 响应式设计 */
@media (max-width: 768px) {
  .user-avatars {
    padding: 0 12px 16px;
  }
  
  .avatars-container {
    gap: 12px;
  }
  
  .avatar-image,
  .share-icon {
    width: 40px;
    height: 40px;
  }
  
  .avatar-status {
    width: 10px;
    height: 10px;
  }
  
  .avatar-label,
  .share-label {
    font-size: 11px;
  }
  
  .plus-icon {
    font-size: 18px;
  }
}
</style>
